package PangModel;
// need to import the ImageStore to include imageID
import java.awt.*;

/**
 * Created by Semih on 23.04.2015.
 */
public abstract class GameObject
{
    protected static final double G = 0.2; // how fast balls will accelerate

    public static final int Y = 106;
    public static final int X = 107;

    protected static final int GAME_NUMBER_OF_LIVES = 3;
    protected static final int GAME_ANIMAL_DURATION_TIME = 5000;
    protected static final int GAME_IMMUNITY_TIME = 3000;

    protected static final int BALL_RADIUS_BIG = 12;
    protected static final int BALL_RADIUS_MID = 7;
    protected static final int BALL_RADIUS_SMALL = 3;

    protected static final int HERO_WIDTH = 50;
    protected static final int HERO_HEIGHT = 50;

    protected static final int UNIT_SPEED = 1; // SO EVERY SPEED IS A MULTIPLE OF THE UNIT_SPEED
    protected static final int MGBULLET_SPEED_Y = 1;
    protected static final int MGBULLET_SPEED_X = 1;

    protected static final int SPLITTED_BALL_SPEED_Y = 1;
    protected static final int SPLITTED_BALL_SPEED_X = 3;

    protected static final int POWERUP_DROP_SPEED = 1;

    protected static final int ROPE_DEFAULT_DIRECTION  = 108;

    protected static final int  ROPE_SPEED = 10;
    protected static final int  HERO_SPEED = 5;

    protected static final int NULL_SPEED = 0;

    // and continue

    public static final int LEFT = 100; //those values just specify, their integer values do not CORRESPOND TO ANY MEANINGFUL THING
    public static final int RIGHT = 101;
    public static final int MGBULLET_DIRECTION_LEFT = 102;
    public static final int MGBULLET_DIRECTION_RIGHT = 103;

    public static final int BALL_SPLITTED_DIRECTION_LEFT = 104;
    public static final int BALL_SPLITTED_DIRECTION_RIGHT = 105;

    protected Point coordinates; // x and y values for the gameObject
    protected Point direction; // includes both direction and speed, in a vector format
    protected double height;
    protected double width;
    protected int imageID;

    private double margin; // maybe includes method should include a little margin

   // abstract void  setDirection(int direction);

    public boolean includes(GameObject go)
    {
       Point p = go.getCoordinates();
       return includes(p.getX(), p.getY(), go.getWidth(), go.getHeight());
    }

    public boolean includes(double x, double y, double otherWidth, double otherHeight) // alter the algorithm with the margin in the mind
    {

        boolean result;
        if((x < coordinates.getX() && x + otherWidth < coordinates.getX()) ||
                (x > coordinates.getX() + getWidth() && x + otherWidth > coordinates.getX() + getWidth() ))
        {result =false;}
        else if((y < coordinates.getY() && y + otherHeight < coordinates.getY()) ||
                (y > coordinates.getY() + getHeight() && y + otherHeight > coordinates.getY() + getHeight() ))
        {result= false;}
        else
            result=true;


        //System.out.println("IM ALIVE!!!!"); dsfsfsf :P
        return result;
    }

    public void  move() // need to check if it is on the border of the gamePanel, first
    {
        coordinates.setLocation(coordinates.getX() + direction.getX()*UNIT_SPEED,
                                coordinates.getY() + direction.getY()*UNIT_SPEED);
    }

    public void draw(Graphics graph)
    {
        ImageStore im = new ImageStore();
        double x = coordinates.getX();
        double y = coordinates. getY();
        try {
            graph.drawImage(ImageStore.getImage(imageID), (int)x, (int)y, null);
        } catch (UnsupportedArgumentException e) {
            e.printStackTrace();
        }
        //graph.drawImage(ImageStore.getImage(ImageID),x,y); //or something, decide when view is done
    }

    public Point getCoordinates()
    {
        return coordinates;
    }

    public int getImageID()
    {
        return imageID;
    }

    public void setDirection(Point direction) {
        this.direction = direction;
    }

    public void setDirection(double x, double y)
    {
        Point p = new Point();
        p.setLocation(x, y);
        setDirection(p);
    }

    public void setCoordinates(Point coor)
    {
        coordinates = coor;
    }
    public void setCoordinates(double x, double y)
    {
        Point p = new Point();
        p.setLocation(x, y);
        setCoordinates(p);
    }

    public double getHeight() {
        return height;
    }

    public double getWidth() {
        return width;
    }
}
